﻿@using Microsoft.FluentUI.AspNetCore.Components.Tests.Extensions
@using Xunit;
@inherits TestContext
@code
{
    [Fact]
    public void FluentIcon_Default()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@icon" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Type()
    {
        // Arrange && Act
        var cut = Render(@<FluentIcon Icon="SampleIcons.Samples.Info" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_SlotTitle()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@icon" Slot="start" Title="My title" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Color()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@icon" Color="Color.Info" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Type_Color()
    {
        // Arrange && Act
        var cut = Render(@<FluentIcon Icon="SampleIcons.Samples.Info" Color="Color.Info" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_CustomColor()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@icon" Color="Color.Custom" CustomColor="#ff0000" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_CustomColor_RequiresColorAttribute()
    {
        Assert.Throws<ArgumentException>(() =>
        {
            // Arrange && Act
            var icon = new SampleIcons.Samples.Info();
            var cut = Render(@<FluentIcon Value="@icon" CustomColor="#ff0000" />);

            // Assert an exception because Color=Color.Custom is required
        });
    }

    [Fact]
    public void FluentIcon_Width()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@icon" Width="100px" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Width_EmptyString()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@icon" Width="" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_OnClick()
    {
        var isClicked = false;

        // Arrange
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@icon" OnClick="@(e => isClicked = true)" />);

        // Act
        cut.Find("svg").Click();

        // Assert
        Assert.True(isClicked);
    }

    [Fact]
    public void FluentIcon_ButtonStart()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentButton IconStart="@icon">My Button</FluentButton>);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_FromImage()
    {
        // Arrange && Act
        var cut = Render(@<FluentIcon Value="@(Icon.FromImageUrl("./logo.png"))" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_FromEmptyImage()
    {
        // Arrange && Act
        var icon = new IconFromImage();

        // Assert
        Assert.Empty(icon.Content);

    }
    [Fact]
    public void FluentIcon_Icon_WithColorRed()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@(icon.WithColor("red"))" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_WithCustomColorRed()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@(icon.WithColor("red"))" Color="Color.Custom" />);

        // Assert
        var html = cut.Markup;

        Assert.Contains("red", html);
    }

    [Fact]
    public void FluentIcon_Icon_WithColorRed_OverridenByColor()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@(icon.WithColor("red"))" Color="Color.Info" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_WithColorSuccess()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<FluentIcon Value="@(icon.WithColor(Color.Success))" />);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_ToMarkup()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<div>@icon.ToMarkup()</div>);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_ToMarkupSize()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<div>@icon.ToMarkup(size: "100px")</div>);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_ToMarkupColor()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.Info();
        var cut = Render(@<div>@icon.ToMarkup(color: "blue")</div>);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_ToMarkupCustomIcon()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.MyCircle();
        var cut = Render(@<div>@icon.ToMarkup()</div>);

        // Assert
        cut.Verify();
    }

    [Fact]
    public void FluentIcon_Icon_ToMarkupCustomIcon_SizeColor()
    {
        // Arrange && Act
        var icon = new SampleIcons.Samples.MyCircle();
        var cut = Render(@<div>@icon.ToMarkup(size: "20px", color: "blue")</div>);

        // Assert
        cut.Verify();
    }
}
